/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean.timer;



import com.bean.timer.interfaces.TimerButtonIcon;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JButton;

/**
 *
 * @author Lukasz
 */

public class TimerButton extends JButton{
    
    TimerButtonIcon icon = TimerButtonIcon.START;
    
    public TimerButton(){
        this.setPreferredSize(getMinimumSize());
    }
    
    @Override
    public void paintComponent(Graphics g){
       
      Graphics2D g2 = (Graphics2D) g.create();
      g2.setPaint(getBackground());
      g2.fillRoundRect(0, 0, getWidth(), getHeight(), 30, 30);
      g2.setPaint(getForeground());
      Dimension d = getSize();
      int w = d.width;
      int h = d.height;
      /*switch(icon){
          case START:
              int[] xPoints = new int[]{0,0,w};
              int[] yPoints = new int[]{h,0,h/2};
              g2.fillPolygon(xPoints, yPoints, 3);
              break;
          
      }*/
      drawCenteredString(getText(), w, h, g2);
      g2.dispose();
    }
   private void drawCenteredString(String s, int w, int h, Graphics2D g2) {
    FontMetrics fm = g2.getFontMetrics();
    int x = (w - fm.stringWidth(s)) / 2;
    int y = (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2);
    g2.drawString(s, x, y);
   }
}